/*
 * hierarchy.c
 *
 *  Created on: Aug 12, 2012
 *      Author: baris
 */

#include <Judy.h>
#include "../model/datatypes.h"
#include "../model/limits.h"

void compute_concept_hierarchy(TBox* tbox) {
	PWord_t pvalue;
	// Index for iterating over the atomic concepts. The index is the
	// concept name and the value is the pointer to the atomic concept
	uint8_t atomic_concept_index[MAX_CONCEPT_NAME_LENGTH];
	// Index for iterating over the subsumers of an atomic concept. Index is
	// the pointer, value is 0 or 1.
	Word_t subsumer_index;
	int is_subsumer_list_nonempty;

	// start with the smallest concept name
	atomic_concept_index[0] = '\0';
	JSLF(pvalue, tbox->atomic_concepts, atomic_concept_index);

	while (pvalue != NULL) {
		// printf("%s: ", atomic_concept_index);
		subsumer_index = 0;
		J1F(is_subsumer_list_nonempty, ((Concept*) *pvalue)->subsumers, subsumer_index);
		while (is_subsumer_list_nonempty) {
			if (((Concept*) subsumer_index)->type != ATOMIC_CONCEPT) {
				J1N(is_subsumer_list_nonempty, ((Concept*) *pvalue)->subsumers, subsumer_index);
				continue;
			}
			// printf("%lu ", subsumer_index);
			// printf("%s ", ((Concept*) subsumer_index)->description.atomic->name);
			J1N(is_subsumer_list_nonempty, ((Concept*) *pvalue)->subsumers, subsumer_index);
		}
		// printf("\n");
		JSLN(pvalue, tbox->atomic_concepts, atomic_concept_index);
	}

}


